package br.com.util;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Handler;

import com.fragments.AtualizaSpeech;


public class CustomProgressDialog implements AtualizaSpeech{

	private Handler handler = new Handler();
	private ProgressDialog progressDialog;
	private Activity activity;
	private Class classe;


	public CustomProgressDialog(Activity activity, Class classe) {
		this.activity = activity;
		this.classe = classe;
		buildProgress();
		// TODO Auto-generated constructor stub
	}

	private void buildProgress() {
		progressDialog = new ProgressDialog(activity);
		progressDialog.setCancelable(false);
		progressDialog.setIndeterminate(false);
		progressDialog.setMax(100);
		progressDialog.setProgress(0);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.setTitle("Processando dados...");
		progressDialog.setMessage("Aguarde um momento");

	}

	private void finalizeContext() {
        activity.startActivity(new Intent(activity,classe));
        activity.finish();
	}


	public void processoAlternativo() {
		try {
			int counter = 0;
			while (counter <= 200) {
				Thread.sleep(10);
				counter++;
				progressDialog.setProgress(counter);
				
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			progressDialog.dismiss();
			handler.post(new Runnable() {
				@Override
				public void run() {
					finalizeContext();
				}
			});
		}
	}

	public void show() {
		//fragmentNext = fragment;
		progressDialog.show();
	}

	
}
